From: Ludovic CHEVALIER Date: Fri, 17 Feb 2017 15:43:04 +0000 (+0100) Subject: Initial commit X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/%22%7B%24link%5B%27href%27%5D%7D/%40%20%27icone_configuration%27%20=%3E%20%27Configuration%27%2C%20%27icone_creer_auteur%27%20=%3E%20%27Create%20a%20new%20author%20and%20associate%20him/her%20with%20this%20article%27%2C%20%27icone_creer_mot_cle%27%20=%3E%20%27Create%20a%20new%20keyword%20and%20link%20it%20to%20this%20article%27%2C-%27icone_creer_mot_cle_rubrique%27%20=%3E%20%27Create%20a%20new%20keyword%20and%20attach%20it%20to%20this%20section%27%2C-%27icone_creer_mot_cle_site%27%20=%3E%20%27Create%20a%20new%20keyword%20and%20attach%20it%20to%20this%20site%27%2C%20%27icone_creer_rubrique_2%27%20=%3E%20%27Create%20a%20new%20section%27%2C%20%27icone_edition%27%20=%3E%20%27Edit%27%2C-%27icone_envoyer_message%27%20=%3E%20%27Send%20this%20message%27%2C%20%27icone_ma_langue%27%20=%3E%20%27My%20language%27%2C%20%27icone_mes_infos%27%20=%3E%20%27My%20details%27%2C%20%27icone_mes_preferences%27%20=%3E%20%27Preferences%27%2C%20%27icone_modifier_article%27%20=%3E%20%27Edit%20this%20article%27%2C-%27icone_modifier_message%27%20=%3E%20%27Edit%20this%20message%27%2C%20%27icone_modifier_rubrique%27%20=%3E%20%27Edit%20this%20section%27%2C%20%27icone_publication%27%20=%3E%20%27Publish%27%2C%20%27icone_relancer_signataire%27%20=%3E%20%27Contact%20the%20signatory%20again%27%2C%40%40%20-220%2C15%20%20188%2C11%20%40%40%20Do%20not%20submit%20this%20import%20request.%3Cp%3EFor%20more%20information%2C%20please%20see%20%3Ca%20href=?a=commitdiff_plain;h=a7382b2309e1f7a02aebab52c1c17fd77b5c5541;p=lhc%2Foe_alcatel_export.git Initial commit --- a7382b2309e1f7a02aebab52c1c17fd77b5c5541 diff --git a/alcatel_export.py b/alcatel_export.py new file mode 100644 index 0000000..01ea6d9 --- /dev/null +++ b/alcatel_export.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import psycopg2 +from lxml import etree + +# variables +db_name = "heureuxcyclage" +db_user = "bikecoop" +db_host = "localhost" +limit = 0 + + +# sql connect +conn = psycopg2.connect("dbname=%s user=%s host=%s" % (db_name, db_user, db_host)) +cur = conn.cursor() + +# import datas in dicos +query = "SELECT name, phone, mobile, is_company from res_partner where name != '/' and name is not null and (phone is not null or mobile is not null) and active = True and is_company = True" +cur.execute(query) + +root = etree.Element('directory') +group = etree.SubElement(root, 'DIR_GROUP') + +line = 0 +for row in cur: + line += 1 + fields = { + 'LINE_NUMBER': '0', + 'BLOCK': '0', + 'RINGER': '0', + } + if row[1]: + fields['NUMBER_WORK'] = unicode(str(row[1]), 'utf-8') + if row[2]: + fields['NUMBER_MOBILE'] = unicode(str(row[2]), 'utf-8') + if row[3]: + fields['NAME_LAST'] = unicode(row[0], 'utf-8') + else: + name = unicode(row[0], 'utf-8') + try: + pspace = name.index(' ') + fields['NAME_FIRST'] = name[:pspace] + fields['NAME_LAST'] = name[pspace+1:] + except ValueError: + fields['NAME_FIRST'] = name + + entry = etree.SubElement(group, 'DIR_ENTRY') + + for field in fields: + entry_field = etree.SubElement(entry, 'DIR_ENTRY_%s' % field.upper()) + entry_field.text = fields[field] + + if limit: + if line == limit: + break + +# sql disconnect +cur.close() +conn.close() + +content = '\n%s' % etree.tostring(root, pretty_print=True) +print(content)